package com.rh.bmw4s.view.fragdialog;

import android.app.DialogFragment;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rh.bmw4s.R;
import com.rh.bmw4s.utills.ScreenUtils;
import com.rh.bmw4s.utills.SizeUtils;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;


/**
 * 回收二手车界面
 * 选择车辆工况 内饰 外观
 */

public class SelectStateDialog extends DialogFragment implements View.OnClickListener {

    private TextView tvCancel, tvTitle;
    private LinearLayout linearLayout1, linearLayout2, linearLayout3, linearLayout4;
    private TextView tvContent1, tvContent2, tvContent3, tvContent4;
    private List<String> strDatas;

    private int type; //1工况状况  2 车辆内饰 3外观状况

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public void onStart() {
        super.onStart();
        //获取屏幕信息
        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

        Window window = getDialog().getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;//ScreenUtils.getScreenWidth()
        // params.height = WindowManager.LayoutParams.MATCH_PARENT;//ScreenUtils.getScreenHeight()
        params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        window.setAttributes(params);
//        window.setGravity(Gravity.CENTER);
//        //这里用屏幕高度，不覆盖状态栏
        //window.setLayout((int) (metrics.widthPixels / 2), ScreenUtils.getScreenHeight());
        //设置布局部分的背景色
        window.setBackgroundDrawable(new ColorDrawable(000000));
        //整体背景色(设置透明度)
        window.setDimAmount(0.5f);
        //动画
        //window.setWindowAnimations(R.style.BottmoDialogAnim2);
        getDialog().setCanceledOnTouchOutside(false);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.custom_selectstate_frag, container);

        tvCancel = view.findViewById(R.id.tv_selectstate_cancel);
        tvTitle = view.findViewById(R.id.tv_selectstate_title);
        linearLayout1 = view.findViewById(R.id.ll_selectstate_you);
        linearLayout2 = view.findViewById(R.id.ll_selectstate_liang);
        linearLayout3 = view.findViewById(R.id.ll_selectstate_zhong);
        linearLayout4 = view.findViewById(R.id.ll_selectstate_cha);
        tvContent1 = view.findViewById(R.id.tv_selectstate_1);
        tvContent2 = view.findViewById(R.id.tv_selectstate_2);
        tvContent3 = view.findViewById(R.id.tv_selectstate_3);
        tvContent4 = view.findViewById(R.id.tv_selectstate_4);

        linearLayout1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (stateItemClickListener!=null){
                    stateItemClickListener.stateItemSelect("优");
                }
            }
        });
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (stateItemClickListener!=null){
                    stateItemClickListener.stateItemSelect("良");
                }
            }
        });
        linearLayout3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (stateItemClickListener!=null){
                    stateItemClickListener.stateItemSelect("中");
                }
            }
        });
        linearLayout4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (stateItemClickListener!=null){
                    stateItemClickListener.stateItemSelect("差");
                }
            }
        });


        tvCancel.setOnClickListener(this);

        if (type == 1) {
            tvTitle.setText("工况状况");
            getGongKuangData();
        } else if (type == 2) {
            tvTitle.setText("车辆内饰");
            getNeiData();
        } else {
            tvTitle.setText("外观状况");
            getWaiData();
        }

        return view;
    }

    private void getGongKuangData() {
        tvContent1.setText(getResources().getString(R.string.gongkuang_nice));
        tvContent2.setText(getResources().getString(R.string.gongkuang_good));
        tvContent3.setText(getResources().getString(R.string.gongkuang_middle));
        tvContent4.setText(getResources().getString(R.string.gongkuang_bad));
    }

    private void getNeiData() {
        tvContent1.setText(getResources().getString(R.string.neishi_nice));
        tvContent2.setText(getResources().getString(R.string.neishi_good));
        tvContent3.setText(getResources().getString(R.string.neishi_middle));
        tvContent4.setText(getResources().getString(R.string.neishi_bad));
    }

    private void getWaiData() {
        tvContent1.setText(getResources().getString(R.string.waiguan_nice));
        tvContent2.setText(getResources().getString(R.string.waiguan_good));
        tvContent3.setText(getResources().getString(R.string.waiguan_middle));
        tvContent4.setText(getResources().getString(R.string.neishi_bad));
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_selectstate_cancel:
                getDialog().dismiss();
                break;
        }
    }


    //定义接口
    public interface OnStateItemClickListener {
        void stateItemSelect(String strState);
    }

    private OnStateItemClickListener stateItemClickListener;

    public void setStateItemClickListener(OnStateItemClickListener stateItemClickListener) {
        this.stateItemClickListener = stateItemClickListener;
    }
}
